import { EllipsisOutlined, PlusOutlined } from '@ant-design/icons';
import { ActionType, ProCard, ProColumns,EditableProTable,ProFormField, } from '@ant-design/pro-components';
import { ProTable, TableDropdown } from '@ant-design/pro-components';
import { Button, ConfigProvider, Dropdown, Form, Input, Space, Tag, message } from 'antd';
import { TyWalletItem, TableListPagination } from './data';
import { useRef, useState } from 'react';
import { reqTyWalletList, reqDeleteTyWallet } from '@/services/tywallet';

const TyWalletTable = ({row,onDataItems}) => {
	const actionRef = useRef<any>();
	const [editableKeys, setEditableRowKeys] = useState<React.Key[]>([]);
	const [dataSource, setDataSource] = useState<readonly TyThaliConfigItemItem[]>([]);
	const [form] = Form.useForm();
	const PopconfirmTitle = `确认删除吗？此操作不可撤销 `;

	const handleChange = (items:any)=>{
		let dataItems:any = [];
		items.map((item:any)=>{
			let {id, index,createrId,delFlag,gmtCreate,gmtModify,lastModifyId,...tmpItem} = item;
			dataItems.push(tmpItem);
		});
		setDataSource(items);
		onDataItems(dataItems);
	}


	const handleTableList = async (params: TableListPagination) => {
		Object.assign(params,{"pageNum":params.current});
		Object.assign(params,{"tyPatientId":row?.id});
		const res = await reqTyWalletList(params);
		if (res?.resultCode === '00000000') {
			const { patientWalletList, total } = res?.data;
			return {
				data: patientWalletList,
				success: true,
				total: total,
			};
		}
	};

	const handleProjectList = async (params: TableListPagination) => {
		Object.assign(params,{"pageNum":params.current});
		console.log("===>",row)
		Object.assign(params,{"tyPatientId":row?.id});
		const res = await reqTyWalletList(params);
		if (res?.resultCode === '00000000') {
			const { patientProjectList, total } = res?.data;
			return {
				data: patientProjectList,
				success: true,
				total: total,
			};
		}
	};

	const columns: ProColumns<TyWalletItem>[] = [
		{
			title: '账号类型',
			dataIndex: 'type',
			valueEnum:{1: { text: '余额账户',},2: { text: '包时账户',},3: { text: '信用账户',},},
		},
		{
			title: '金额',
			dataIndex: 'balance',
		},
	];

	const projectcolumns: ProColumns<TyWalletItem>[] = [
		{
			title: '项目',
			dataIndex: 'tyProjectName',
		},
		{
			title: '数量',
			dataIndex: 'quantity',
		},
	];
	
	return (
		<>
		<ProTable<TyWalletItem>
			columns={columns}
			search={false}
			actionRef={actionRef}
			request={(params): Promise<any> => handleTableList(params)}
			pagination={{pageSize: 10,}}
		/>
		<ProTable<TyWalletItem>
			columns={projectcolumns}
			search={false}
			actionRef={actionRef}
			request={(params): Promise<any> => handleProjectList(params)}
			pagination={{pageSize: 10,}}
		/>
		</>
	)
}

export default TyWalletTable;

